//
//  LGAdminLoginVC.m
//  ALS3.0
//
//  Created by guomianxiang on 2017/4/19.
//  Copyright © 2017年 guomianxiang. All rights reserved.
//

#import "LGAdminLoginVC.h"
#import "ALSHeader.h"
#import "LoginWindow.h"

#define k_loginWindow [LoginWindow shareLoginWindw]

@interface LGAdminLoginVC ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UILabel *presentationLab;

@end

@implementation LGAdminLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.passwordTextField.tintColor = kALSHightBlueColor;
    self.passwordTextField.delegate = self;
//    self.passwordTextField.returnKeyType
//    self.passwordTextField.returnKeyType

//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

}

- (void)keyboardWillShow:(NSNotification *)notification {
    NSDictionary *userInfo = notification.userInfo;
    NSValue *value = userInfo[UIKeyboardFrameEndUserInfoKey];
    CGFloat keyBoardHeight = [value CGRectValue].size.height;
    NSLog(@"%f",keyBoardHeight);
}

- (void)viewDidAppear:(BOOL)animated {
//    NSLog(@"%@",self.presentedViewController);
//    NSLog(@"%@",self.presentingViewController);
//    NSLog(@"%@",self.presentationController);
//    NSLog(@"%@",self);
}

- (IBAction)dimissBtn:(UIButton *)sender {
    [self.view endEditing:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

//登录
- (IBAction)login {
    [self.view endEditing:YES];
    if ([self validPassword]) {

        [k_loginWindow showAdminLoginSuccessHUDAndDismiss];
        [MobClick event:UMEventAdminLogin];

    }
}

- (BOOL)validPassword {
    //密码为空
    if (self.passwordTextField.text.length == 0) {
        self.presentationLab.text = @"密码不能为空";
        self.presentationLab.hidden = NO;
        return NO;
    }
    //密码正确 - 超级管理员
    if ([ALSSupervisorPassword isEqualToString:self.passwordTextField.text]) {
        [NSUD setBool:YES forKey:ALSAdministrators];
        self.presentationLab.hidden = YES;
        return YES;
    }
    
    //密码不为空 错误
    self.presentationLab.text = @"密码错误";
    self.presentationLab.hidden = NO;
    return NO;
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [self login];
    
    return YES;
}// called when 'return' key pressed. return NO to ignore.


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.passwordTextField resignFirstResponder];
//    [self.view endEditing:YES];
    [self validPassword];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
